package dang.action.order;

import dang.action.DangAction;
import dang.action.cart.Cart;
import dang.common.CookieUtil;
import dang.dao.DaoFactory;
import dang.dao.OrderDao;
import dang.entity.ReceiveAddress;
import dang.entity.User;

public class ProcessOrder extends DangAction{
	private ReceiveAddress address;
	
	public String execute() throws Exception {
		User user=(User) session.get("user");
		int id = user.getId();
		address.setUser_id(id);
		OrderDao dao = DaoFactory.getOrderDao();
		if(address.getId()==-1)
			dao.saveAddress(address);
		//订单成功 完成cart
		Cart cart = (Cart) session.get("cart");
		cart.clear();
		String cartInfoId=(String) session.get("cartInfoId").toString();
		CookieUtil.saveCookie("cartInfo"+cartInfoId, cart.store(), response);
		return "success";
	}

	public ReceiveAddress getAddress() {
		return address;
	}

	public void setAddress(ReceiveAddress address) {
		this.address = address;
	}
	
}
